home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- */
-
- /* modified from uudecode.c V 5.3 from Berkeley 1/22/85 for use with */
- /* T3DLIB by Rob Hounsell */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- /* single character decode */
- #define DEC(c) (((c) - ' ') & 077)
-
- /*
- * copy from buffer to out, decoding as you go along.
- */
- decode_data(out, buffer)
- FILE *out;
- char *buffer;
- {
- char *bp;
- int n, bytecount, len, char_index;
-
- bytecount = 0;
-
- char_index = 0;
- len = (int)strlen(buffer);
- while (len > 0) {
- n = DEC(buffer[char_index]);
- if (n <= 0)
- return(n);
- bytecount += n;
-
- bp = &buffer[char_index+1];
- while (n > 0) {
- outdec(bp, out, n);
- len -= 4;
- char_index += 4;
- bp += 4;
- n -= 3;
- }
- char_index++; /* to account for the size byte for this run of */
- len--; /* up to 45 chars. */
- }
- return(bytecount);
- }
-
- /*
- * output a group of 3 bytes (4 input characters).
- * the input chars are pointed to by p, they are to
- * be output to file f. n is used to tell us not to
- * output all of them at the end of the file.
- */
- outdec(p, f, n)
- char *p;
- FILE *f;
- {
- int c1, c2, c3;
-
- c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
- c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
- c3 = DEC(p[2]) << 6 | DEC(p[3]);
- if (n >= 1)
- putc(c1, f);
- if (n >= 2)
- putc(c2, f);
- if (n >= 3)
- putc(c3, f);
- }
-